//
//  ViewController.swift
//  TouchIDSwiftDemo
//
//  Created by HaiSheng on 15/7/17.
//  Copyright (c) 2015年 huanghaisheng. All rights reserved.
//

import UIKit
import LocalAuthentication

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        TouchIDStart()
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    func TouchIDStart() {
    
        let authenticationContext = LAContext()
        var error: NSError?
        
        let isTouchIdAvailable = authenticationContext.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: &error)
        
        if isTouchIdAvailable {
        
            println("指纹识别功能可疑使用")
            
            authenticationContext.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "通过Home键验证已有手机指纹", reply: { (success, error) -> Void in
                
                if success {
                    println("指纹识别成功")
                } else {
                    println("指纹识别失败")
                }
            })
            
        } else {
            println("抱歉，指纹识别功能不可以使用！\n\(error)")
        }
    }
    
}

